package whf.file.web;

import whf.file.entity.Folder;
import whf.file.service.FolderServiceImp;
import whf.framework.entity.AbstractEntity;
import whf.framework.web.struts.WebData;
import whf.framework.web.struts.WebDispatchAction;
import whf.framework.web.struts.WebForward;

/**
 * @author wanghaifeng
 * @create Nov 25, 2006 2:08:29 PM
 * 
 */
public class FolderAction extends WebDispatchAction {

	/* (non-Javadoc)
	 * @see whf.framework.web.struts.WebDispatchAction#prepareCreate(whf.framework.entity.AbstractEntity, whf.framework.web.struts.WebData)
	 */
	@Override
	public WebForward prepareCreate(AbstractEntity baseForm, WebData data) throws Exception {
		long parentId = data.getLongParameter("parentFolderId", 0);
		if(parentId > 0){
			Folder parent = FolderServiceImp.getFolderService().findByPrimaryKey(parentId);
			((Folder)baseForm).setParent(parent);
		}
		return super.prepareCreate(baseForm, data);
	}

	/* (non-Javadoc)
	 * @see whf.framework.web.struts.WebDispatchAction#create(whf.framework.entity.AbstractEntity, whf.framework.web.struts.WebData)
	 */
	@Override
	public WebForward create(AbstractEntity baseForm, WebData data) throws Exception {
		WebForward f = super.create(baseForm, data);
		Folder parent = ((Folder)baseForm).getParent();
		if(parent != null){
			data.setAttribute("_$_parentFolderId", parent.getId());
		}
		return f;
	}

	/* (non-Javadoc)
	 * @see whf.framework.web.struts.WebDispatchAction#update(whf.framework.entity.AbstractEntity, whf.framework.web.struts.WebData)
	 */
	@Override
	public WebForward update(AbstractEntity baseForm, WebData data) throws Exception {
		WebForward f = super.update(baseForm, data);
		Folder parent = ((Folder)baseForm).getParent();
		if(parent != null){
			data.setAttribute("_$_parentFolderId", parent.getId());
		}
		return f;
	}

}